'use strict';

angular.module('snPaas_om')
	.controller('ClusterCtrl',['$scope','baseUrl','ngDialog','clusterStore','SpSlider',function($scope,baseUrl,ngDialog,clusterStore,SpSlider){
		var vm = $scope;
		vm.baseUrl = baseUrl.static;
		vm.newSolution = function(){
			var d = ngDialog.open({
				template: baseUrl.static+'template/views/newSolution.html',
				controller: 'NewSolutionCtrl',
				width:830
			});
			d.closePromise.then(function(){
				init();
			});
		};
		var init = function(){
			clusterStore.query().then(function(data){
				vm.clusterList = data;
			});	
		};
		init();
		vm.remove = function(item){
			var d = ngDialog.open({
				template: baseUrl.static+'template/views/confirm.html',
				controller: 'ConfirmCtrl',
				width:430,
				data:{
					text:'确定要删除集群'+item.deploymentName+'吗？'
				},
				closeByEscape:false,
				closeByDocument:false,
				showClose:false
			});
			d.closePromise.then(function(res){
				if(res.value =='yes'){
					clusterStore.remove(item.deployId).then(function(){
						SpSlider.slideIn({
							title:'操作成功',
							content:'集群 '+item.deploymentName+' 已删除',
							type:'noti'
						});
						init();
					});
				}
			});
			
			
		};
		
	}]);